﻿var grid = null;
$(function () {
    $("#txtStartDate,#txtEndDate,#txtExpireStartDate,#txtExpireEndDate").ligerDateEditor({
        showTime: false,
        format: "yyyy-MM-dd",
        width: 100,
        cancelable: true
    });

    var isDeptAll = 0;
    if ($("#hdnJobTitle").val().indexOf("护理部") > -1) isDeptAll = 1;
    $("#ddlDepartmentCode").ligerComboBox({
        cancelable: false,
        width: 100,
        url: "/Escort/EscortPersonnel/GetDepartmentList?isAll=" + isDeptAll + "&ram" + Math.random(),
        valueField: "value",
        textField: "text",
        valueFieldID: 'hdnDepartmentCode',
        value: $("#hdnJobTitle").val().indexOf("护理部") > -1 ? "-1" : $("#hdnCurrDepCode").val()
    });

    $("#ddlComeFrom").ligerComboBox({
        cancelable: false,
        width: 100,
        url: "/Escort/EscortPersonnel/GetBaseCommonDict?isAll=1&dictName=OUT_COME_DICT&ram" + Math.random(),
        valueField: "ITEM_CODE",
        textField: "ITEM_NAME",
        valueFieldID: 'hdnComeFrom',
        value: -1
    });

    $("#ddlESCORT_TYPE").ligerComboBox({
        cancelable: false,
        width: 75,
        data: [
              { id: 1, text: "临时" },
              { id: 2, text: "长期" }
        ],
        valueFieldID: 'hdnESCORT_TYPE',
        value: 2
    });

    $("#ddlKeyAreaFlag").ligerComboBox({
        cancelable: false,
        width: 60,
        data: [
              { id: -1, text: "请选择" },
              { id: 1, text: "有" },
              { id: 0, text: "无" }
        ],
        valueFieldID: 'hdnKeyAreaFlag',
        value: -1
    });

    $("#btnExport").click(function () {
        var startDate = $("#txtStartDate").val();
        var endDate = $("#txtEndDate").val();
        var departmentCode = $("#hdnDepartmentCode").val();
        var expireStartDate = $("#txtExpireStartDate").val();
        var expireEndDate = $("#txtExpireEndDate").val();
        var comeFrom = $("#hdnComeFrom").val();
        var escortType = $("#hdnESCORT_TYPE").val();
        var keyAreaFlag = $("#hdnKeyAreaFlag").val();
        var url = "/Escort/EscortPersonnel/ExpireExport?startDate=" + startDate + "&endDate=" + endDate + "&departmentCode=" + departmentCode + "&expireStartDate=" + expireStartDate + "&expireEndDate=" + expireEndDate + "&comeFrom=" + comeFrom + "&escortType=" + escortType + "&keyAreaFlag=" + keyAreaFlag;
        Export(url);
    });

    $('#btnSearch').click(function () {
        search();
    });

    $('#btnSearch').click();
});

//搜索
function search(pageNumber) {
    var queryData = {
        startDate: $("#txtStartDate").val(),
        endDate: $("#txtEndDate").val(),
        expireStartDate: $("#txtExpireStartDate").val(),
        expireEndDate: $("#txtExpireEndDate").val(),
        departmentCode: $("#hdnDepartmentCode").val(),
        comeFrom: $("#hdnComeFrom").val(),
        escortType: $("#hdnESCORT_TYPE").val(),
        keyAreaFlag: $("#hdnKeyAreaFlag").val()
    }
    initTable(queryData, pageNumber);
}

var KINSHIP_DICT = [];
var KEY_AREAS_DICT = [];

//加载列表
function initTable(queryData, pageNumber) {
    grid = $("#maingrid").ligerGrid({
        height: '100%',
        url: '/Escort/EscortPersonnel/SearchExpire?ram=' + Math.random(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: true,
        heightDiff: -5,
        columns: [
            { display: '患者床号', name: 'BED_NO', width: 80 },
            { display: '患者姓名', name: 'PATIENT_NAME', width: 80 },
            { display: '患者状态', name: 'STATUS', width: 80 },
            { display: '住院号', name: 'PATIENT_ID', width: 80 },
            { display: '病区', name: 'NURSE_CELL_NAME', width: 100 },
            { display: '陪护姓名', name: 'ESCORT_NAME', width: 80 },
            { display: '陪护开始日期', name: 'START_DATE', width: 100 },
            {
                display: '陪护停止时间', name: 'STOP_DATE', width: 120, render: function (row) {
                    return row.STOP_DATE.substring(0,row.STOP_DATE.length - 3);
                }
            },
            { display: '陪护年龄', name: 'ESCORT_AGE', width: 80 },
            {
                display: '陪护性别', name: 'ESCORT_SEX_NAME', width: 80, render: function (row) {
                    if (IsEmpty(row.ESCORT_ID)) return "";
                    else return row.ESCORT_SEX_NAME;
                }
            },
            { display: '陪护联系方式', name: 'ESCORT_PHONE', width: 140 },
            {
                display: '与患者亲属关系', name: 'KINSHIP', width: 120, render: function (row) {
                    if (IsEmpty(row.ESCORT_ID)) return "";
                    for (var i = 0; i < KINSHIP_DICT.length; i++) {
                        if (row.KINSHIP == KINSHIP_DICT[i].value) {
                            return KINSHIP_DICT[i].text;
                        }
                    }
                }
            },
            { display: '陪护籍贯', name: 'ADDR_NAME', width: 80 },
            { display: '证件类型', name: 'ID_CARD_TYPE_NAME', width: 80 },
            { display: '证件号', name: 'ID_CARD_NO', width: 150 },
            {
                display: '陪护联系地址', name: 'ADDR_DETAIL', width: 250, render: function (row) {
                    return row.ADDR_DETAIL.replace(/#/g, "")
                }
            },
            {
                display: '陪护人员来源', name: 'OUT_COME_FLAG', width: 100, render: function (row) {
                    return $("#ddlComeFrom").ligerComboBox().findTextByValue(row.OUT_COME_FLAG);
                }
            },
            {
                display: '健康码', name: 'HEALTH_CODE_TYPE', width: 100, render: function (row) {
                    if (row.HEALTH_CODE_TYPE == 1) {
                        return "绿码";
                    }
                    else if (row.HEALTH_CODE_TYPE == 2) {
                        return "橙码";
                    }
                    else if (row.HEALTH_CODE_TYPE == 3) {
                        return "红码";
                    }
                    else {
                        return "无";
                    }
                }
            },
            {
                display: '来泉日期', name: 'COME_FROM_DATE', width: 100, render: function (row) {
                    return row.COME_FROM_DATE.split(' ')[0];
                }
            },
            {
                display: '重点疫区接触史', name: 'KEY_AREAS_FLAG', width: 100, render: function (row) {
                    if (IsEmpty(row.ESCORT_ID)) return "";
                    if (row.KEY_AREAS_FLAG == 1)
                        return "有";
                    else
                        return "无";
                }
            },
            {
                display: '重点疫区接触地', name: 'KEY_AREAS_DESC', width: 250, render: function (row) {
                    if (IsEmpty(row.ESCORT_ID)) return "";
                    var html = "";
                    for (var i = 0; i < KEY_AREAS_DICT.length; i++) {
                        if ((';' + row.KEY_AREAS_DESC + ';').indexOf(';' + KEY_AREAS_DICT[i].value + ';') > -1) {
                            html += KEY_AREAS_DICT[i].text + ";";
                        }
                    }
                    return html;
                }
            },
            {
                display: '是否境外归国人员', name: 'ABROAD_FLAG', width: 100, render: function (row) {
                    if (IsEmpty(row.ESCORT_ID)) return "";
                    if (row.ABROAD_FLAG == 1)
                        return "是";
                    else
                        return "否";
                }
            },
            {
                display: '归国日期', name: 'ENTRY_DATE', width: 100, render: function (row) {
                    return row.ENTRY_DATE.split(' ')[0];
                }
            },
            { display: '境外国家', name: 'ABROAD_COUNTRY', width: 100 },
            {
                display: '有无流行病史', name: 'EPIDEMIC_FLAG', width: 100, render: function (row) {
                    if (IsEmpty(row.ESCORT_ID)) return "";
                    if (row.EPIDEMIC_FLAG == 1)
                        return "有";
                    else
                        return "无";
                }
            },
            {
                display: '有无临床症状', name: 'CLINIC_SYMP_FLAG', width: 100, render: function (row) {
                    if (IsEmpty(row.ESCORT_ID)) return "";
                    if (row.CLINIC_SYMP_FLAG == 1)
                        return "有";
                    else
                        return "无";
                }
            }
        ],
        onSuccess: function (data, grid) {
            if (KINSHIP_DICT.length == 0) {
                $.ajax({
                    url: "/Escort/EscortPersonnel/GetBaseCommonDict?dictName=KINSHIP_DICT",
                    type: "GET",
                    async: false,
                    success: function (data) {
                        var jsonData = $.parseJSON(data);
                        for (var i = 0; i < jsonData.length; i++) {
                            KINSHIP_DICT.push({ text: jsonData[i].ITEM_NAME, value: jsonData[i].ITEM_CODE });
                        }
                    }
                });
            }
            if (KEY_AREAS_DICT.length == 0) {
                $.ajax({
                    url: "/Escort/EscortPersonnel/GetBaseCommonDict?dictName=KEY_AREAS_DICT",
                    type: "GET",
                    async: false,
                    success: function (data) {
                        var jsonData = $.parseJSON(data);
                        for (var i = 0; i < jsonData.length; i++) {
                            KEY_AREAS_DICT.push({ text: jsonData[i].ITEM_NAME, value: jsonData[i].ITEM_CODE });
                        }
                    }
                });
            }
        }
    });
    GridNoData($("#maingrid"));
}